package com.qiyuexinxi.chat.controller;

import com.qiyuexinxi.chat.common.GenericResponse;
import com.qiyuexinxi.chat.constants.api.LoginApi;
import com.qiyuexinxi.chat.dto.request.CompleteInfoRequest;
import com.qiyuexinxi.chat.dto.request.GetPhoneCodeRequest;
import com.qiyuexinxi.chat.dto.request.LoginRequest;
import com.qiyuexinxi.chat.dto.request.RegisterRequest;
import com.qiyuexinxi.chat.service.impl.LoginServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author yangxingyu
 * @date 2020/2/27
 * @description
 */
@RestController
@Api(description = "登录注册相关接口")
public class LoginController {

    @Autowired
    LoginServiceImpl loginService;

    @PostMapping(value = LoginApi.REGISTER, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "注册用户", notes = "注册用户")
    public GenericResponse register(@Valid @RequestBody RegisterRequest registerReques){
        return new GenericResponse(loginService.register(registerReques));
    }

    @PostMapping(value = LoginApi.COMPLETE_INFORMATION, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "完善信息", notes = "完善信息")
    public GenericResponse completeInfo(@Valid @RequestBody CompleteInfoRequest completeInfoRequest){
        return new GenericResponse(loginService.completeInfo(completeInfoRequest));
    }

    @PostMapping(value = LoginApi.LOGIN, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "登录", notes = "登录")
    public GenericResponse login(@Valid @RequestBody LoginRequest loginReques){
        return new GenericResponse(loginService.login(loginReques));
    }

    @PostMapping(value = LoginApi.RE_PASSWORD, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "找回密码", notes = "找回密码")
    public GenericResponse rePassword(@Valid @RequestBody RegisterRequest registerRequest){
        return new GenericResponse(loginService.rePassword(registerRequest));
    }

    @PostMapping(value = LoginApi.GET_PHONE_CODE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "获取手机验证码", notes = "获取手机验证码")
    public GenericResponse getPhoneCode(@Valid @RequestBody GetPhoneCodeRequest getPhoneCodeReques){
        return new GenericResponse(loginService.getPhoneCode(getPhoneCodeReques.getPhone()));
    }



}
